Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/http language support #5778

Open
wants to merge 69 commits into
base: main
Choose a base branch
from
Open

Conversation

koros
Copy link
Contributor

@koros koros commented Nov 14, 2024

Add support for HTTP snippet generation as a language option.

koros added 30 commits October 9, 2024 16:10
@Onokaev Onokaev marked this pull request as draft January 15, 2025 12:10
@Onokaev Onokaev marked this pull request as ready for review January 17, 2025 09:16
@@ -4,3 +4,11 @@ public static class Constants
public const string DefaultOpenApiLabel = "default";
public const string TempDirectoryName = "kiota";
}

public enum Authentication
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to a dedicated file, give it a more explicit name


if (config.Language == GenerationLanguage.HTTP && openApiDocument is not null)
{
await settingsFileManagementService.WriteSettingsFileAsync(config.OutputPath, openApiDocument, cancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add logs to track the step like other steps before

}
}

private void AddHttpSecurity(CodeClass codeClass, OpenApiSecurityScheme securityScheme)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opportunity to refactor to more concise code with the switch since all that's changing is the name


public AuthenticationSettings()
{
HostAddress = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialization can be done directly on the properties.
use string.Empty instead

private static SettingsFile GenerateSettingsFile(OpenApiDocument openApiDocument)
{
var settings = new SettingsFile();
settings.EnvironmentVariables.Development.HostAddress = openApiDocument.Servers[0].Url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check a server is present first

.Where(static property => property.IsOfKind(CodePropertyKind.QueryParameter))
.ToList();

queryParameters.AddRange(queryParams);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a select many instead, and combine the linq statements to reduce allocations

var pathParameters = requestBuilderClass
.GetChildElements(true)
.OfType<CodeProperty>()
.Where(property => property.IsOfKind(CodePropertyKind.PathParameters) && !property.Name.Equals("pathParameters", StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then use a constant reference instead please

{
// Retrieve the base URL property from the request builder class
return requestBuilderClass.Properties
.FirstOrDefault(property => property.Name.Equals("BaseUrl", StringComparison.OrdinalIgnoreCase))?.DefaultValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a constant

Comment on lines +296 to +299
if (processedClasses == null)
{
processedClasses = new HashSet<CodeClass>();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (processedClasses == null)
{
processedClasses = new HashSet<CodeClass>();
}
processedClasses ??= new HashSet<CodeClass>();

namespace Kiota.Builder.Writers.Http;
public class CodePropertyWriter(HttpConventionService conventionService) : BaseElementWriter<CodeProperty, HttpConventionService>(conventionService)
{
public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter writer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we at least make a generic NO-OP writer, that we could reuse, to avoid the duplication?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress 🚧
Development

Successfully merging this pull request may close these issues.

4 participants